PROJECT(ossim-planet)
MESSAGE("**********************Setting up ossim-planet********************")
INCLUDE(OssimVersion)
INCLUDE(OssimUtilities)
INCLUDE(OssimCommonVariables)

OPTION(OSSIMPLANET_ENABLE_EPHEMERIS "Set to ON enable ephemeris support if GPSTK is found.  Use OFF to not enable ephemeris." ON)

IF(NOT APPLE)
  cmake_minimum_required(VERSION 2.6)
ELSE(NOT APPLE)
  cmake_minimum_required(VERSION 2.8)
ENDIF(NOT APPLE)

find_package(OpenThreads)
find_package(ossim)
find_package(OssimVideo)
find_package(GPSTK)
find_package(JPEG)
find_package(OSG)
find_package(OssimWMS)
find_package(ZLIB)
find_package(OpenGL)
find_package(FFmpeg)
find_package(Regex)

MESSAGE( STATUS "OSSIM_INCLUDE_DIR         = ${OSSIM_INCLUDE_DIR}")
MESSAGE( STATUS "OSSIM_LIBRARIES           = ${OSSIM_LIBRARIES}")
MESSAGE( STATUS "OPENGL_INCLUDE_DIR        = ${OPENGL_INCLUDE_DIR}")
MESSAGE( STATUS "OPENGL_LIBRARIES          = ${OPENGL_LIBRARIES}")
MESSAGE( STATUS "OSSIM_LIBRARIES           = ${OSSIM_LIBRARIES}")
MESSAGE( STATUS "OSSIMVIDEO_LIBRARIES   = ${OSSIMVIDEO_LIBRARIES}")
MESSAGE( STATUS "OSSIMVIDEO_INCLUDE_DIR = ${OSSIMVIDEO_INCLUDE_DIR}")
MESSAGE( STATUS "OPENTHREADS_LIBRARY       = ${OPENTHREADS_LIBRARY}")
MESSAGE( STATUS "OPENTHREADS_INCLUDE_DIR   = ${OPENTHREADS_INCLUDE_DIR}")
MESSAGE( STATUS "FFMPEG_LIBRARIES = ${FFMPEG_LIBRARIES}")
MESSAGE( STATUS "FFMPEG_INCLUDE_DIRS = ${FFMPEG_INCLUDE_DIRS}")
MESSAGE( STATUS "OSSIMWMS_LIBRARY               = ${OSSIMWMS_LIBRARY}")
MESSAGE( STATUS "OSSIMWMS_INCLUDE_DIR           = ${OSSIMWMS_INCLUDE_DIR}")

MESSAGE( STATUS "OSG_LIBRARY               = ${OSG_LIBRARY}")
MESSAGE( STATUS "OSG_INCLUDE_DIR           = ${OSG_INCLUDE_DIR}")
MESSAGE( STATUS "OSGUTIL_LIBRARY           = ${OSGUTIL_LIBRARY}")
################################################## BUILD THE LIBRARY #######################################
SET(LIB_NAME ossim-planet)

INCLUDE_DIRECTORIES(${${PROJECT_NAME}_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${OSSIM_INCLUDE_DIR})

IF(OSSIMVIDEO_FOUND AND BUILD_OSSIM_VIDEO)
   INCLUDE_DIRECTORIES(${OSSIMVIDEO_INCLUDE_DIR})
   ADD_DEFINITIONS("-DOSSIMPLANET_ENABLE_PREDATOR")
   INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
ELSE(OSSIMVIDEO_FOUND AND BUILD_OSSIM_VIDEO)
   MESSAGE(STATUS "Disabling Predator support in Planet")
   SET(OSSIMVIDEO_LIBRARY "")
   SET(OSSIMVIDEO_LIBRARIES "")
   SET(OSSIMVIDEO_INCLUDE_DIR "")
   SET(FFMPEG_LIBRARIES "")
   SET(FFMPEG_LIBRARY "")
ENDIF(OSSIMVIDEO_FOUND AND BUILD_OSSIM_VIDEO)

INCLUDE_DIRECTORIES(${OPENTHREADS_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${OSSIMWMS_INCLUDE_DIR})

IF(GPSTK_FOUND AND OSSIMPLANET_ENABLE_EPHEMERIS)
    MESSAGE(STATUS "GPSTK_LIBRARY               = ${GPSTK_LIBRARY}")
    MESSAGE(STATUS "GPSTK_INCLUDE_DIR           = ${GPSTK_INCLUDE_DIR}")
    ADD_DEFINITIONS("-DOSSIMPLANET_ENABLE_EPHEMERIS")
    INCLUDE_DIRECTORIES(${GPSTK_INCLUDE_DIR})
    IF(REGEX_FOUND)
      INCLUDE_DIRECTORIES(${REGEX_INCLUDE_DIR})
      MESSAGE(STATUS "REGEX_INCLUDE_DIR          =  ${REGEX_INCLUDE_DIR}")
      MESSAGE(STATUS "REGEX_LIBRARIES            =  ${REGEX_LIBRARIES}")
    ELSE()
      set(REGEX_LIBRARIES "")
    ENDIF()
ELSE(GPSTK_FOUND AND OSSIMPLANET_ENABLE_EPHEMERIS)
    SET(GPSTK_LIBRARY "")
ENDIF(GPSTK_FOUND AND OSSIMPLANET_ENABLE_EPHEMERIS)


INCLUDE_DIRECTORIES(${OSG_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})


FILE(GLOB OSSIMPLANET_SRCS RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/src/ossimPlanet/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/ossimPlanet/*.c")
FILE(GLOB OSSIMPLANET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/ossimPlanet/*.h")

IF(NOT BUILD_OSSIM_VIDEO)
   LIST(REMOVE_ITEM OSSIMPLANET_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/ossimPlanet/ossimPlanetPredatorVideoLayerNode.cpp")
   LIST(REMOVE_ITEM OSSIMPLANET_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/ossimPlanet/ossimPlanetPredatorVideoLayerNode.h")
ENDIF()

IF(NOT WIN32)
   LIST(REMOVE_ITEM OSSIMPLANET_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/ossimPlanet/iowin32.c")
ELSE(NOT WIN32)
   LIST(APPEND ${LIB_NAME}_EXTRA_LIBS "ws2_32" "winmm")
ENDIF(NOT WIN32)

SET(INSTALL_INCLUDE_DIR "include/ossimPlanet")
OSSIM_LINK_LIBRARY(${LIB_NAME} COMPONENT_NAME ossim TYPE "${OSSIM_USER_DEFINED_DYNAMIC_OR_STATIC}" HEADERS ${OSSIMPLANET_HEADERS} SOURCE_FILES ${OSSIMPLANET_SRCS} 
                   LIBRARIES ${OSSIM_LIBRARIES} ${OSGVIEWER_LIBRARY} ${OSGDB_LIBRARY} ${OSGGA_LIBRARY}  ${OSGTEXT_LIBRARY} ${OSGUTIL_LIBRARY}  ${OSG_LIBRARY}  ${OPENTHREADS_LIBRARY} ${JPEG_LIBRARY} ${OSSIMWMS_LIBRARY} ${GPSTK_LIBRARY} ${OSSIMVIDEO_LIBRARY} ${ZLIB_LIBRARY} ${OPENGL_LIBRARIES} ${FFMPEG_LIBRARIES} ${REGEX_LIBRARIES}
                   INSTALL_LIB INSTALL_HEADERS VERSION_SYMLINKS ADDITIONAL_COMPILE_FLAGS "-DOSSIMPLANET_LIBRARY")


############################################################# SETUP APPLICATIONS ##################################################
set(TARGET_COMMON_LIBRARIES ${LIB_NAME} ${OSSIMVIDEO_LIBRARIES})
FILE(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/examples/ossimplanetviewer/*.cpp")
OSSIM_SETUP_APPLICATION(ossimplanetviewer INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES})
FILE(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/examples/ossimplanettest/*.cpp")
OSSIM_SETUP_APPLICATION(ossimplanettest INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES})
IF(BUILD_OSSIM_VIDEO)
   FILE(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/examples/ossimplanetklv/*.cpp")
   OSSIM_SETUP_APPLICATION(ossimplanetklv INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES})
ENDIF()

FILE(GLOB SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/apps/ossimplanet-chip/*.cpp")
OSSIM_SETUP_APPLICATION(ossimplanet-chip INSTALL COMMAND_LINE COMPONENT_NAME ossim SOURCE_FILES ${SOURCE_FILES})

####################################### SETUP THE UNINSTALL #################################
OSSIM_ADD_COMMON_MAKE_UNINSTALL()
